list_example = [10, 1.23, "like this", True, None]
print(list_example)
type(list_example)[10, 1.23, 'like this', True, None]
list
Jake Starkey
February 18, 2024
*A value is datum (literal) such as a number or text
*There are different types of values:
*352.3 is known as a float or double;
*22 is an integer;
*“Hello World!” is a string.
[10, 1.23, 'like this', True, None]
list
[10, 1.23, ‘like this’, True, None]
*The most. basic built-in data types that we’ll need to know about are: integers, 10 floats, 1.23 strings, “like this” booleans, True nothing, None
*Python also has a built-in type of data container called a list (ex. [10,15,20]) that can contain anything, even different types
##Values, Variables, and Types
*A variable is a name that refers to a value.
**We can think of a variable as a box that has a value, or multiple values, packed inside it A variable is just a name!
*Sometimes you will hear variables referred to as objects.
*Everything that is not a literal value, such as 10, is an object
##Assignment (=)
17
*In Python, we use = to assign a value to a variable
*In math, = means equality of both sides
*In programs, = means assignment: assign the value on the right side to the variable on the left side.
*In programming code, everything on the right side needs to have a value.
*The right side can be a literal value, or a variable that has already been assigned a value, or a combination.
*When Python reads y= x + 12, it does the following: Sees the = in the middle.Knows that this is an assignment.
*Calculates the right side (gets the value of the object referred to by x and adds it to 12).
*Assigns the result to the left-side variable, y.
##Code and Comment Style
*The two main principles for coding and managing data are: Make things easier for your future self. Don’t trust your future self.
*The # mark is Google Colab’s comment character The # character has many names: hash, sharp, pound, or octothorpe. The # indicates that the rest of the line is to be ignored. **Write comments before the line that you want the comment to apply to.
*Consider adding more comments on code cells and their results using text cells.
##Brackets *There are several kinds of brackets in Python, including [], {}, and ().
*[] is used to denote a list or to signify accessing a position using an index
{'first_letter': 'a', 'second_letter': 'b'}
{‘first_letter’: ‘a’, ‘second_letter’: ‘b’} {} is used to denote a set or a dictionary (with key-value pairs)
*() is used to denote a tuple, or the arguments to a function, ex. function(x) where x is the input passed to the function ##Q1
##Q2
*This is saying 20 is not equal to ‘20’ because they are different data types (int vs string)
True This says the expression is true since 3.5 < 4
##Q3
Write a Python code that uses slicing and the print() function to print out the following message:
The total trip cost is: $12.80
The total trip cost is: $12.80
##Q4
Write a Python code that uses print() and max() functions to print out the largest value in the list, list_variable, as follows:
The largest value in the list is: 1000
The largest value in the list is: 1000
The largest value in the list is: 1000 ##Q5 Import the pandas library as pd. Install the itables package. *From itables, import the function init_notebook_mode and show.
Requirement already satisfied: itables in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (1.6.3)
Requirement already satisfied: IPython in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from itables) (8.15.0)
Requirement already satisfied: pandas in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from itables) (2.0.3)
Requirement already satisfied: numpy in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from itables) (1.24.3)
Requirement already satisfied: backcall in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from IPython->itables) (0.2.0)
Requirement already satisfied: decorator in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from IPython->itables) (5.1.1)
Requirement already satisfied: jedi>=0.16 in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from IPython->itables) (0.18.1)
Requirement already satisfied: matplotlib-inline in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from IPython->itables) (0.1.6)
Requirement already satisfied: pickleshare in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from IPython->itables) (0.7.5)
Requirement already satisfied: prompt-toolkit!=3.0.37,<3.1.0,>=3.0.30 in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from IPython->itables) (3.0.36)
Requirement already satisfied: pygments>=2.4.0 in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from IPython->itables) (2.15.1)
Requirement already satisfied: stack-data in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from IPython->itables) (0.2.0)
Requirement already satisfied: traitlets>=5 in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from IPython->itables) (5.7.1)
Requirement already satisfied: pexpect>4.3 in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from IPython->itables) (4.8.0)
Requirement already satisfied: appnope in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from IPython->itables) (0.1.2)
Requirement already satisfied: python-dateutil>=2.8.2 in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from pandas->itables) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from pandas->itables) (2023.3.post1)
Requirement already satisfied: tzdata>=2022.1 in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from pandas->itables) (2023.3)
Requirement already satisfied: parso<0.9.0,>=0.8.0 in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from jedi>=0.16->IPython->itables) (0.8.3)
Requirement already satisfied: ptyprocess>=0.5 in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from pexpect>4.3->IPython->itables) (0.7.0)
Requirement already satisfied: wcwidth in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from prompt-toolkit!=3.0.37,<3.1.0,>=3.0.30->IPython->itables) (0.2.5)
Requirement already satisfied: six>=1.5 in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from python-dateutil>=2.8.2->pandas->itables) (1.16.0)
Requirement already satisfied: executing in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from stack-data->IPython->itables) (0.8.3)
Requirement already satisfied: asttokens in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from stack-data->IPython->itables) (2.0.5)
Requirement already satisfied: pure-eval in /Users/jakestarkey/anaconda3/lib/python3.11/site-packages (from stack-data->IPython->itables) (0.2.2)